package logic

import (
	"bawei_shop/api/pkg"
	"context"
	"time"

	"bawei_shop/api/internal/svc"
	"bawei_shop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginLogic) Login(req *types.LoginRequest) (resp *types.Response, err error) {
	//手机号格式验证
	//短信验证码验证
	//查询手机号在用户表中是否存在，不存在的话不能登录,否则登录成功
	//生成token
	token, _ := pkg.GetJwtToken("", time.Now().Unix(), 86400, "1")

	return &types.Response{
		Code: 0,
		Msg:  "登录成功",
		Data: map[string]interface{}{
			"token": token,
		},
	}, nil
}
